// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import GameConfig, { COLOR, ShapeData, ShapeType } from "../GameConfig";
import Utlis from "../Utlis";
import Shape, {  } from "./Shape";

const {ccclass, property} = cc._decorator;

@ccclass
export default class ShapeManager extends cc.Component {

    

    private static instance: ShapeManager;
    public static getInstance(): ShapeManager {
        if (!this.instance) {
            const node = new cc.Node("ShapeManager");
            cc.find("Canvas").addChild(node);
            this.instance = node.addComponent(ShapeManager);
        }
        return this.instance;
    }

    private list:Array<Shape> = new Array<Shape>();

    async onLoad() {
        
    }

    public createShape(shapeData:ShapeData) {
        const shape = new Shape();
        shape.init(shapeData);
        this.list.push(shape);
        return shape;
    }

    protected update(dt: number): void {
        for (let i = 0; i < this.list.length; i++) {
            this.list[i].update(dt);
        }
    }

    

    // public destroyShape(shape:Shape) {
    //     shape.destroy();
    // }

    
}
